package com.yixin.controller;

import com.yixin.entity.Result;
import com.yixin.entity.Role;
import com.yixin.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @PostMapping
    public Result add(@RequestBody Role role) {
        roleService.add(role);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody Role role) {
        roleService.update(role);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        roleService.deleteById(id);
        return Result.success();
    }

    @GetMapping
    public Result findAll() {
        return Result.success(roleService.findAll());
    }
}
